﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HSchSchedule.Utils;
using WebSysCore;

namespace HSchSchedule.UC
{
    public partial class LoginUC : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ValidateUser();
            }
        }

        private void ValidateUser()
        {
            if (Session[GUIConstants.LOGIN_SESSION] == null)
            {
                //Session.Clear();
                btnLogout.Visible = false;
                //Response.Redirect("~/BackendPage/MasterPage.aspx");
            }
            else
            {
                Customer c = (Customer)Session[GUIConstants.LOGIN_SESSION];
                lblUserOniline.Text = c.LoginName;
            }
        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            Session.Clear();
            if (Request.Cookies[GUIConstants.LOGIN_COOKIES] != null)
            {
                HttpCookie loginCookies = Request.Cookies[GUIConstants.LOGIN_COOKIES];
                loginCookies.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(loginCookies);
            }
            Response.Redirect("~/BackendPage/MasterPage.aspx");
        }
    }
}